{% extends "base.html" %}
{% block content %}
{% ifequal is_con 0 %}
<script type="text/javascript" src="/static/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/static/js/jquery-ui-1.8.16.custom.min.js"></script>
<link href="/static/css/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
<div class="form-div" style="margin:10px;">
  <form action='' method='get' name="searchForm">
	<table>
		<tr>
			<td style="border:0px;padding:3px;">
				<img src="/static/images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH">
			</td>
			<td style="border:0px;padding:3px;">
				Date Start:<input type='text' name='starttime' id='start' value="">
				Date End:<input type='text' name='endtime' id='end'>
			</td>
			<td style="border:0px;padding:3px;">
				Sales:<select name='s_id' id='s_id' style="color:#cc33ff" onchange='$("input#search").click()'>
						<option value=0>All</option>
						{%for sale in sales%}
						<option value="{{sale.id}}">{{sale.name}}</option>
						{%endfor%}
					</script>
				<input type='button' id="search" value='Search'/>
			</td>
		</tr>
		<tr>
			<td style="border:0px;padding:3px;"></td>
			<td colspan='10' style="border:0px;padding:3px;">
				<div class="selectdate" days='7'>Weekly</div>
				<div class="selectdate" days='14'>Bi-weekly</div>
				<div class="selectdate" days='30'>Monthly</div>
				<div class="selectdate" days='90'>Season</div>
				<div class="selectdate" days='180'>Half-yearly</div>
				<div class="selectdate" days='365'>Yearly</div>
			</td>
		</tr>
	</table>
  </form>
  <form action="/report_export/" method='post' id='post_report'>
	<input type='hidden' name='d' value=''/>
	<input type='hidden' name='t' value=''/>
  </form>
</div>
<script type="text/javascript" src="/static/js/create_report_export.js"></script>
<script>
$(document).ready(
	function(){
    	$('#start').datepicker({"dateFormat": "yy-mm-dd",changeMonth:true,changeYear:true})
		$('#end').datepicker({"dateFormat": "yy-mm-dd",changeMonth:true,changeYear:true})
		var agodays = new Date(Date.parse(new Date().toString()) - 86400000*6);
		var year = agodays.getUTCFullYear()
		var month = (agodays.getUTCMonth()+1)>=10?(agodays.getUTCMonth()+1):'0'+(agodays.getUTCMonth()+1)
		var day = agodays.getUTCDate()>=10?agodays.getUTCDate():'0'+agodays.getUTCDate()
		var date = year+'-'+month+'-'+day
		$('#start').val(date)
		
		$('div.selectdate').click(function(){
			$('div.selectdate').removeClass('active_title')
			$('div.selectdate').css('background','')
			$(this).css('background','#defdef')
			$(this).addClass('active_title')
		})
	}
)

$("input#search").bind({
	click:function(){
		var t = this
		if(t.style.cursor == 'wait'){
			return false;
		}
		t.style.cursor = 'wait'
		var data = $('form[name="searchForm"]').serializeArray()
		var datas = {'is_con':1,'t':Math.random()}
		for(var i=0;i<data.length;i++){
			datas[data[i].name] = data[i].value
		}
		$.ajax({
			url:'',
			data:datas,
			type:'get',
			dataType:'html',
			success:function(e){
				t.style.cursor = 'pointer'
				$('#conreturn').html(e)
			}
		})
	}
})
</script>
{% endifequal %}
<style>
td{
	padding:2px;
	border:1px dotted #333;
}
th{
	background:#FFFFCD;
	border:1px dotted #333;
	padding:2px;
}
.selectdate{
	width:auto;float:left;padding:3px;background:#fff;border:1px dotted #333;margin:2px;cursor:pointer;
}
.selectdate:hover{
	background:#defdef;
}
</style>
<div id="conreturn" style="margin:10px;">
	{%if error_info%}
		<span class='red'>{{error_info}}</span>
	{%else%}
	<table style="background:#defdef" >
		<tr>
			<td colspan="20"  style="border:1px solid #333;">
				<table width='100%'>
				  <tr>
					<td colspan='2' align='left' style="line-height:25px;background:#FFFFCD;border:0px;padding:3px;"><strong id='report_title'>Recruitment Report <span id='date_title'></span> <span id='sale_title'></span></strong></td>
					<td style="line-height:25px;background:#FFFFCD;border:0px;padding:3px;width:200px;"><strong>Sales Person:</strong>&nbsp;<span id='sales'></span></td>
					<td colspan='2' align='right' style="line-height:25px;background:#FFFFCD;border:0px;padding:3px;"><strong>Date:</strong>&nbsp;
					<span id="report_start">{{begin|date:"M d,Y"}}</span> - {{end|date:"M d,Y"}}</td>
				  </tr>
				</table>
			</td>
		</tr>
		<tr align='center'>
			<td colspan='3'><b>New Lead</b></td>
			<td><b>Potential Candidate</b></td>
		</tr>
		<tr valign='top'>
			<td style="border:0px;padding:3px;" valign='top'>
				<table calss='sontable' width="200px;" style="border: 1px dotted #000000;padding:10px;background:#fff;" >
					<tr align='center'><th colspan='2'>By Source</th></tr>
					<tr><th>Source</th><th># of Lead</th></tr>
					{%for source in source_ret%}
						<tr align='center'>
							<td>{{source.0}}</td>
							<td>{{source.1}}</td>
						<tr>
					{%endfor%}
					<tr height='20px'>
						<td></td><td></td>
					</tr>
					<tr align='center' style="border-top: 1px solid #000000">
						<td>Subtotal:</td>
						<td>{{source_total}}</td>
					</tr>
					<tr align='center'>
						<td>Repeat:</td>
						<td>{%if source_status.8%}{{source_status.8}}{%else%}0{%endif%}</td>
					</tr>
					<tr align='center'>
						<td>Overseas:</td>
						<td>{%if source_status.11%}{{source_status.11}}{%else%}0{%endif%}</td>
					</tr>
					<tr align='center'>
						<td>TL:</td>
						<td>{{tl_nums}}</td>
					</tr>
				</table>
			</td>
			<td style="border:0px;padding:3px;" valign='top'>
				<table calss='sontable' width="200px;" style="border: 1px dotted #000000;padding:10px;background:#fff;" >
					<tr align='center'><th colspan='2'>By Program</th></tr>
					<tr><th>Program</th><th># of Lead</th></tr>
					{%for project in project_ret%}
						<tr align='center'>
							<td>{{project.0}}</td>
							<td>{{project.1}}</td>
						<tr>
					{%endfor%}
					<tr height='20px'>
						<td></td><td></td>
					</tr>
					<tr align='center' style="border-top: 1px solid #000000">
						<td>Subtotal:</td>
						<td>{{project_total}}</td>
					</tr>
					<tr align='center'>
						<td>Repeat:</td>
						<td>{%if project_status.8%}{{project_status.8}}{%else%}0{%endif%}</td>
					</tr>
					<tr align='center'>
						<td>TL:</td>
						<td>{{ptl_nums}}</td>
					</tr>
				</table>
			</td>
			<td style="border:0px;padding:3px;" valign='top'>
				<table calss='sontable' width="200px;" style="border: 1px dotted #000000;padding:10px;background:#fff;" >
					<tr align='center'><th colspan='2'>By Status</th></tr>
					<tr><th>Status</th><th># of Lead</th></tr>
					{%for status in status_ret%}
						<tr align='center'>
							<td>{{status.0}}</td>
							<td>{{status.1}}</td>
						<tr>
					{%endfor%}
					<tr height='20px'>
						<td></td><td></td>
					</tr>
					<tr align='center' style="border-top: 1px solid #000000">
						<td>Subtotal:</td>
						<td>{{status_total}}</td>
					</tr>
				</table>
			</td>
			<td style="padding:3px;" valign='top'>
				<table calss='sontable' width="300px;" style="border: 1px dotted #000000;padding:10px;background:#fff;" >
					<tr align='center' height='20px'><th colspan='3'></th></tr>
					<tr><th>Program</th><th>Interest Level</th><th># of Prospect</th></tr>
					{%for cand in cand_ret%}
						<tr align='center'>
							<td>{{cand.0}}</td>
							<td>SI</td>
							<td>{{cand.1}}</td>
						<tr>
						<tr align='center'>
							<td></td>
							<td>LI</td>
							<td>{{cand.2}}</td>
						<tr>
					{%endfor%}
					<tr height='20px'>
						<td></td><td></td><td></td>
					</tr>
					<tr align='center' style="border-top: 1px solid #000000">
						<td>Subtotal:</td>
						<td>SI:</td>
						<td>{{si_num}}</td>
					</tr>
					<tr align='center'>
						<td></td>
						<td>LI:</td>
						<td>{{li_num}}</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr align='center'>
			<td colspan='2'><b>New Application</b></td>
			<td colspan='2'><b>Enrolled</b></td>
		</tr>
		<tr>
			<td  valign='top'>
				<table calss='sontable' width="200px;" style="border: 1px dotted #000000;padding:10px;background:#fff;" >
					<tr align='center'><th colspan='2'>By Source</th></tr>
					<tr><th>Source</th><th># of Applicant</th></tr>
					{%for source in app_source_ret%}
						<tr align='center'>
							<td>{{source.0}}</td>
							<td>{{source.1}}</td>
						<tr>
					{%endfor%}
					<tr height='20px'>
						<td></td><td></td>
					</tr>
					<tr align='center' style="border-top: 1px solid #000000">
						<td>Subtotal:</td>
						<td>{{app_source_total}}</td>
					</tr>
				</table>
			</td>
			<td style="border:0px;padding:3px;" valign='top'>
				<table calss='sontable' width="200px;" style="border: 1px dotted #000000;padding:10px;background:#fff;" >
					<tr align='center'><th colspan='2'>By Program</th></tr>
					<tr><th>Program</th><th># of Applicant</th></tr>
					{%for project in app_project_ret%}
						<tr align='center'>
							<td>{{project.0}}</td>
							<td>{{project.1}}</td>
						<tr>
					{%endfor%}
					<tr height='20px'>
						<td></td><td></td>
					</tr>
					<tr align='center' style="border-top: 1px solid #000000">
						<td>Subtotal:</td>
						<td>{{app_project_total}}</td>
					</tr>
				</table>
			</td>
			<td valign='top'>
				<table calss='sontable' width="200px;" style="border: 1px dotted #000000;padding:10px;background:#fff;" >
					<tr align='center'><th colspan='2'>By Source</th></tr>
					<tr><th>Source</th><th># of Enrollment</th></tr>
					{%for source in enro_source_ret%}
						<tr align='center'>
							<td>{{source.0}}</td>
							<td>{{source.1}}</td>
						<tr>
					{%endfor%}
					<tr height='20px'>
						<td></td><td></td>
					</tr>
					<tr align='center' style="border-top: 1px solid #000000">
						<td>Subtotal:</td>
						<td>{{enro_source_total}}</td>
					</tr>
				</table>
			</td>
			<td valign='top'>
				<table calss='sontable' width="200px;" style="border: 1px dotted #000000;padding:10px;background:#fff;" >
					<tr align='center'><th colspan='2'>By Program</th></tr>
					<tr><th>Program</th><th># of Enrollment</th></tr>
					{%for source in enro_program_ret%}
						<tr align='center'>
							<td>{{source.0}}</td>
							<td>{{source.1}}</td>
						<tr>
					{%endfor%}
					<tr height='20px'>
						<td></td><td></td>
					</tr>
					<tr align='center' style="border-top: 1px solid #000000">
						<td>Subtotal:</td>
						<td>{{enro_program_total}}</td>
					</tr>
				</table>
			</td>	
		</tr>
	</table>
	<script>
		$('#sales').html($('#s_id option:selected').text())
	</script>
	{%endif%}
</div>
<script>
	var date_title = $('.active_title').text()
	var pro_title = $('#p_id option:selected').text()
	if(date_title){
		$('#date_title').html('('+date_title+')')
	}
	if($('#p_id option:selected').val()!=0){
		$('#pro_title').html(' -'+pro_title)
	}
</script>
{% endblock %}
